package com.pioneer.gui.invoice.view;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import com.pioneer.gui.invoice.model.InvoiceModel;
import com.pioneer.gui.invoice.view.InvoicePanel;

public class Confirmation
extends JDialog
{
	private InvoiceModel model;
	//private InvoicePanel invoicePanel;
	public static final int YES=0;
	public static final int NO=1;
	public static final int CANCEL=2;
	
	public Confirmation(String title,String message,InvoiceModel model)
	{		
		//super(title);
		//this.invoicePanel=invoicePanel;
		this.model=model;
		this.setSize(new Dimension(300,200));
		this.setLocation(300,300);
		JPanel mainPanel=new JPanel();
		
		mainPanel.setLayout(new GridLayout(2,1));
		
		mainPanel.add(new JTextArea(message));
		
		JPanel buttonPanel=new JPanel();
		buttonPanel.setLayout(new FlowLayout());
		JButton yesButton=new JButton("Yes");
		yesButton.addActionListener(new yesListener());
		JButton noButton=new JButton("No");
		noButton.addActionListener(new noListener());
		JButton cancelButton=new JButton("Cancel");
		cancelButton.addActionListener(new cancelListener());
		
		buttonPanel.add(yesButton);
		buttonPanel.add(noButton);
		buttonPanel.add(cancelButton);
		
		mainPanel.add(buttonPanel);
		this.getContentPane().add(mainPanel);
		this.setModal(true);
		this.show();
	}
	
	class yesListener
	implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			Confirmation.this.model.doSave();
			Confirmation.this.dispose();			
		}
	}
	
	class noListener
	implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			Confirmation.this.dispose();			
		}
	}
	
	class cancelListener
	implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			Confirmation.this.model.doRollback();
			//invoicePanel.invoiceNoPanel.invoiceNo.setSelectedItem(Confirmation.this.model.getSelectedInvoiceNo());			
			Confirmation.this.dispose();			
		}
	}
	
}
